
import { categoryClassify,categoryItem } from '@/services';
  
const state = {
  //左侧数据
  categoryList: [],
  //下标
  ind: 0,
  //右侧数据
  rightList: []
};
const getters = {};
const mutations = {
  setState(state, payload) {
    state[payload.key] = payload.value
  }
};

const actions = {
  // 获取左侧分类
  async categoryClassify({ commit }, payload) {
      let result = await categoryClassify();
      commit('setState',{key:'categoryList',value:result})
      let results = await categoryItem(result[0].categoryId);
      commit('setState',{key:'rightList',value:results.records})
  },
  // 点击tab切换
  async changeInd({ commit }, payload){
      commit('setState',{key:'ind',value:payload})
  },
  // 获取右侧数据
  async categoryItem({ commit }, payload){
      let result = await categoryItem(payload);
      commit('setState',{key:'rightList',value:result.records})
  }
};

export default {
  namespaced: true,
  modules: {},
  state,
  getters,
  mutations,
  actions,
}